
// 一、用接口的方式自定义类型

interface IPerson{
    name:string,
    age?:number,
    readonly sex:string,
    isAdult:boolean,
    eat:(food:string)=>void
}

let p1:IPerson = {
    name:"葛佳敏",
    age:18,
    sex:"女",
    isAdult:false,
    eat:function(food:string):void{
        console.log("吃"+food);
        
    }
}


p1.age = 16;
// p1.sex="男"; //不行

p1.eat("油条");


// 二、用type的方式自定义类型

type IBook = {
    name:string,
    author:string,
    price:number,
    pusblish?:string
}

let b1:IBook ={
    name:"西厢记",
    author:"韩琴",
    price:58.2,
    pusblish:"千锋出版社"
}